Page({
  onLoad() {
    this.getAuthCode();
  },
  data: {
    canIUseAuthButton: my.canIUse('button.open-type.getAuthorize'),
    user_id:0,
  },
  getAuthCode: () => {

    // my.getSetting({
    //   success: res => {
    //     const { album = false, location = false } = res.authSetting;
    //     my.alert({ content: `相册已授权：${album}；地理位置已授权：${location}` });
    //   },
    // });
      var that=this;
    my.getAuthCode({
      scopes: 'auth_user',
      success: (res) => {
        console.log('res.authCode');
        console.log(res.authCode);
        my.request({
          //你的服务器地址
          url: 'http://192.168.0.8/api/demo/login',
          method:'post',
          data:{code:res.authCode},
          success(res) {
            // 获取需要的用户信息
            console.log('res')
            console.log(res)

          }
        });     
      },
    });


    // my.getAddress({
    //   success: function(res) {
    //     console.log(res);
    //   },
    //   fail: function(err) {
    //     console.log(err);
    //   }
    // });
    
    
  //   my.getOpenUserInfo({
  //     success: (res) => {
  //         let userInfo = JSON.parse(res.response).response
  //         console.log('userInfo')
  //         console.log(userInfo)
  //         my.request({
  //           //你的服务器地址
  //           url: 'https://zhouqifu.test.xingzong.tech//api/demo/saveMobile',
  //           method:'post',
  //           data: userInfo
  //         });
  //     },
  //     fail: (err) => {
  //         console.log(err)
  //     }
  // });


},

getOrderStr(){
  console.log(4444)
  my.request({
    //你的服务器地址
    url: 'https://zhouqifu.test.xingzong.tech/api/demo/getOrderStr',
    method:'post',
    data:{mobile:18438617276,'order_sn':'20231012152881cats1'},
    success(res) {
      // 唤起授权
      console.log(res)
      console.log('dfgdfgdfg')
      // var data=JSON.parse(res.data)
       var data=res.data
      console.log(data)
      my.paySignCenter({
        signStr:data.data,
        success: function(res) {
          console.log('签约成功');
          console.log(res);
        },
        fail: function(err) {
          console.log('err');
          console.log(err);
        }
      });
    }
  });

},

pay(){
  console.log(4444)
  my.request({
    //你的服务器地址
    url: 'https://zhouqifu.test.xingzong.tech/api/demo/pay',
    method:'post',
    data:{external_agreement_no:'20231010103845cats3'},
    success(res) {
      // 唤起授权
      console.log(res)
      console.log('dfgdfgdfg')
      // var data=JSON.parse(res.data)
       var data=res.data
      console.log(data)
      my.paySignCenter({
        signStr:data.data,
        success: function(res) {
          console.log('扣款成功');
          console.log(res);
        },
        fail: function(err) {
          console.log('扣款失败');
          console.log(err);
        }
      });
    }
  });

},

getPhoneNumber(){
  console.log(2222222222)
  my.getPhoneNumber({
    success: (res) => {
      let encryptedData = res.response;
      console.log('encryptedData');
      console.log(encryptedData);
      my.request({
        //你的服务器地址
        url: 'http://192.168.0.8/api/demo/saveMobile?uid=12',
        dataType:'raw',
        method:'post',
        data: encryptedData,
        success(res) {
          // 获取需要的用户信息
          console.log(res)
        }
      });
    },
    fail: (res) => {
      console.log(res);
    },
  });

},

getOpenUserInfo() {
  my.getOpenUserInfo({
      success: (res) => {
          let userInfo = JSON.parse(res.response).response
          console.log('userInfo')
          console.log(userInfo)
      },
      fail: (err) => {
          console.log(err)
      }
  });
}

});